﻿using CPPEI;
using CPPEI.WebApi;
using SLG.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Ser = SLG.Domain.Services;
using Ent = SLG.Domain.Entities;
using V = SLG.Domain.Views;

namespace SLG.WebApi.City
{
    /// <summary>
    /// 获得城市列表
    /// </summary>
    [AuthGetAction("City", "GetList", "1.0")]
    public class GetListAction : BaseAction<GetListParams, GetListResult>
    {
        protected override ActionResult<GetListResult> OnExecute(ActionContext context, SysParameters sysParams, GetListParams opParams)
        {
            int userId = Convert.ToInt32(context.UserId);

            Ser.QueryService service = new Ser.QueryService();
            ListResult<Ent.T_City> serResult = service.QueryCities(userId);

            if (serResult.IsSuccess)
            {
                GetListResult actResult = new GetListResult();

                for (int index = 0; index < serResult.Data.Count; index++)
                {
                    GetListResult.Item item = new GetListResult.Item();

                    item.Id = serResult.Data[index].Id;
                    item.LordId = serResult.Data[index].LordId;
                    item.Name = serResult.Data[index].Name;
                    item.Area = serResult.Data[index].Area;
                    item.PosX = serResult.Data[index].PosX;
                    item.PosY = serResult.Data[index].PosY;
                    item.Level = serResult.Data[index].Level;
                    item.Experience = serResult.Data[index].Experience;
                    item.CreatedTime = serResult.Data[index].CreatedTime;
                    item.IsCapital = serResult.Data[index].IsCapital;
                    actResult.Items.Add(item);
                }
                return new ActionResult<GetListResult>(actResult);
            }
            else
            {
                return new ActionResult<GetListResult>(serResult);
            }
        }
    }

    public class GetListParams
    {
    }

    public class GetListResult
    {
        public List<Item> Items = new List<Item>();

        public class Item
        {
            public Guid Id { get; set; }

            public Guid LordId { get; set; }

            public string Name { get; set; }

            public int Area { get; set; }

            public int PosX { get; set; }

            public int PosY { get; set; }

            public int Level { get; set; }

            /// <summary>
            /// 经验
            /// </summary>
            public int Experience { get; set; }

            public DateTime CreatedTime { get; set; }

            public bool IsCapital { get; set; }
        }
    }
}
